import Vue from 'vue'
import Vuex from 'vuex'
import { dfs } from '../../utils/index'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        data: [{
            id: '0',
            preId: null,
            isShow: true,
            showtext: false,
            name: 'THE RAINY DAY',
            time: ' 8 hours ago',
            text: 'The palm trees in a row by the lake are smiting their heads against the dismal sky; the crows with their draggled wings are silent on the tamarind branches, and the eastern bank of the river is haunted by a deepening gloom.',
            children: [{
                id: '00',
                preId: '0',
                isShow: true,
                showtext: false,
                name: 'adcyewcg',
                time: ' 9 hours ago',
                text: 'Men have crowded into the flooded field to catch the fishes as they escape from the over-flowing ponds; the rain water is running in rills through the narrow lanes like a laughing boy who has run away from his mother to tease her.',
                children: []
            }, {
                id: '000',
                preId: '0',
                isShow: true,
                showtext: false,
                name: 'adcyewcg',
                time: ' 10 hours ago',
                text: 'The road to the market is desolate, the lane to the river is slippery. The wind is roaring and struggling among the bamboo branches like a wild beast tangled in a net.',
                children: []
            }]
        }],
    },
    mutations: {
        addComment(state, data) {
            if (data.preId) {
                let commentPosition = dfs(state.data, data.preId)
                commentPosition.children.unshift(data)
            } else {
                state.data.unshift(data)
            }
        }
    }
})